package com.broada.apm.dao.impl;

import java.util.List;

import com.broada.apm.dao.AnalyzerDao;
import com.broada.apm.model.Analyzer;
import com.broada.apm.model.PagingList;

public class MysqlAnalyzerDao extends MysqlAbstractDao implements AnalyzerDao{
	
	public static final String ANALYZER_NAMESPACE = "com.broada.apm.dao.AnalyzerDao.";
	
	@Override
	public void addAnalyzer(Analyzer analyzer) {
		getSqlSession().insert(ANALYZER_NAMESPACE + "addAnalyzer", analyzer);
	}

	@Override
	public void deleteAnalyzer(String id) {
		getSqlSession().delete(ANALYZER_NAMESPACE + "deleteAnalyzer", id);
	}

	@Override
	public PagingList<Analyzer> getAllAnalyzer(int pageIndex, int pageSize) {
		List<Analyzer> result = null;
		
		PagingList<Analyzer> page = new PagingList<Analyzer>();
		page.setStartPage(pageIndex);
		page.setPageSize(pageSize);
		
		result = getSqlSession().selectList(ANALYZER_NAMESPACE + "getAllAnalyzer");

		page.setData(result);
		PagingList.pagingHandler(pageIndex, pageSize, (int)page.getTotalRecords(), page);
		return page;
	}

	@Override
	public Analyzer queryAnalyzerByIpAndPort(Analyzer analyzer) {
		return getSqlSession().selectOne(ANALYZER_NAMESPACE + "queryAnalyzerByIpAndPort", analyzer);
	}
	
	@Override
	public Analyzer getAnalyzerById(String analyzerId) {
		return getSqlSession().selectOne(ANALYZER_NAMESPACE + "getAnalyzerById", analyzerId);
	}

	@Override
	public List<Analyzer> getAllAnalyzerNoPage() {
		return getSqlSession().selectList(ANALYZER_NAMESPACE + "getAllAnalyzerNoPage");
	}
}
